package com.panda.system.controller;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.core.page.TableDataInfo;
import com.panda.common.enums.BusinessType;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.system.domain.PandaStore;
import com.panda.system.dto.TBauthModel;
import com.panda.system.service.IPandaStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺信息Controller
 * 
 * @author ruoyi
 * @date 2021-01-02
 */
@RestController
@RequestMapping("/system/store")
public class PandaStoreController extends BaseController
{
    @Autowired
    private IPandaStoreService pandaStoreService;

    /**
     * 查询店铺信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PandaStore pandaStore)
    {
        startPage();
        List<PandaStore> list = pandaStoreService.selectPandaStoreList(pandaStore);
        return getDataTable(list);
    }

    /**
     * 导出店铺信息列表
     */
    @Log(title = "店铺信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PandaStore pandaStore)
    {
        List<PandaStore> list = pandaStoreService.selectPandaStoreList(pandaStore);
        ExcelUtil<PandaStore> util = new ExcelUtil<PandaStore>(PandaStore.class);
        return util.exportExcel(list, "store");
    }

    /**
     * 获取店铺信息详细信息
     */
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return AjaxResult.success(pandaStoreService.selectPandaStoreById(storeId));
    }

    /**
     * 新增店铺信息
     */
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PandaStore pandaStore)
    {
        return toAjax(pandaStoreService.insertPandaStore(pandaStore));
    }

    /**
     * 修改店铺信息
     */
    @Log(title = "店铺信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PandaStore pandaStore)
    {
        return toAjax(pandaStoreService.updatePandaStore(pandaStore));
    }

    /**
     * 删除店铺信息
     */
    @Log(title = "店铺信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(pandaStoreService.deletePandaStoreByIds(storeIds));
    }


    /**
     * 获取系统配置
     */
    @GetMapping("/config")
    public AjaxResult config()
    {
        TBauthModel config = pandaStoreService.querySystemConfig();
        return AjaxResult.success(config);
    }
}
